﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KTFrameworkCus;

public partial class Controls_UCHoiDap : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadHoiDap();   
        }
    }

    protected void loadHoiDap()
    {
        var list = dmsFunction.getCategoryByParent(212).OrderBy(t => t.DisplayOrder).Take(3).ToList();
        rptHoiDap.DataSource = list;
        rptHoiDap.DataBind();
        rptHoiDapList.DataSource = list;
        rptHoiDapList.DataBind();
    }

    protected void rptHoiDap_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        udv_Categories _Categories = (udv_Categories)e.Item.DataItem;
        if (_Categories != null)
        {
            Repeater _rptChildCategories = (Repeater)e.Item.FindControl("rptChild");
            int _categoriesID = _Categories.CateID;
            _rptChildCategories.DataSource = dmsFunction.getAllArticleByCat(_categoriesID).Where(t => t.IsApproved == true).Take(3).ToList();
            _rptChildCategories.DataBind();
        }
    }

    protected void rptChild_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        udv_Articles _Product = (udv_Articles)e.Item.DataItem;
        Image img = e.Item.FindControl("Image1") as Image;
        if (_Product != null)
        {
            if (_Product.test.Value)
            {
                img.Visible = true;
                img.ImageUrl = Page.ResolveUrl("~/images/new_icon.gif");
            }
            else
            {
                img.Visible = false;
            }
        }
        else { img.Visible = false; }

    }
}